What is is-extendable?
The is-extendable npm package is used to check if a value is extendable, meaning if it can have new properties added to it. This is typically used in the context of extending objects in JavaScript, where certain types of values, like null or undefined, cannot be extended.
What are is-extendable's main functionalities?
Checking if an object is extendable
This feature allows you to check if a given value is an object or function that can have new properties added to it. It returns true for plain objects and functions, and false for non-extendable values like null, undefined, and primitives.
const isExtendable = require('is-extendable');
// Returns true for plain objects
console.log(isExtendable({})); // true
// Returns true for functions
console.log(isExtendable(function() {})); // true
// Returns false for non-extendable values
console.log(isExtendable(null)); // false
console.log(isExtendable(undefined)); // false
console.log(isExtendable(123)); // false
Other packages similar to is-extendable
lodash.isplainobject
This package provides a function to check if a value is a plain object, that is, an object created by the Object constructor or one with a null prototype. It is similar to is-extendable in that it helps determine if an object can be extended, but it specifically checks for plain objects.
is-object
is-object is a package that checks if a value is an object and not null. This is a broader check than is-extendable, which not only checks if the value is an object but also if it is extendable.
extend
The extend package is used to extend an object by copying the properties from additional objects to it. While is-extendable is used to check if an object can be extended, extend actually performs the extension.
is-extendable
Returns true if a value is any of the object types: array, regexp, plain object, function or date. This is useful for determining if a value can be extended, e.g. "can the value have keys?"
Install
Install with npm
$ npm i is-extendable --save
Usage
var isExtendable = require('is-extendable');
Returns true if the value is any of the following:
array
regexp
plain object
function
date
error
Notes
All objects in JavaScript can have keys, but it's a pain to check for this, since we ether need to verify that the value is not null
or undefined
and:
- the value is not a primitive, or
- that the object is an
object
, function
Also note that an extendable
object is not the same as an extensible object, which is one that (in es6) is not sealed, frozen, or marked as non-extensible using preventExtensions
.
Related projects
- assign-deep: Deeply assign the enumerable properties of source objects to a destination object.
- extend-shallow: Extend an object with the properties of additional objects. node.js/javascript util.
- isobject: Returns true if the value is an object and not an array or null.
- is-plain-object: Returns true if an object was created by the
Object
constructor. - is-equal-shallow: Does a shallow comparison of two objects, returning false if the keys or values differ.
- kind-of: Get the native type of a value.
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Author
Jon Schlinkert
License
Copyright © 2015 Jon Schlinkert
Released under the MIT license.
This file was generated by verb-cli on July 04, 2015.